import Vue from 'vue'
import Vuex from "vuex"
Vue.use(Vuex)

export default new Vuex.Store({
	// 全局属性变量
	state: { // state的作用是定义属性变量。定义一个参数
		theme: '',
		footTab:'',
		points_name:'积分',
		package_pt:0,
		package_zy:0,
		package_mt:0,
		package_hh:0,
		click_id:''
	},
	// 全局同步方法，在methods{this.$store.commit("changeTheme")}
	mutations: {
		changeTheme(state, value) {
			state.theme = value;
		},
		changefootTab(state, value) {
			state.footTab = value;
		},
		changePoints(state, value) {
			state.points_name = value;
		},
		changePacketPt(state, value) {
			state.package_pt = value;
		},
		changePacketZy(state, value) {
			state.package_zy = value;
		},
		changePacketMt(state, value) {
			state.package_mt = value;
		},
		changePacketHh(state, value) {
			state.package_hh = value;
		},
		setClickID(state,value){
			state.click_id = value
		}
	},
	getters: {
		getPacketPt(state){
			// package_pt==0 从缓存取 
			// if(state.package_pt == 0 && uni.getStorageSync('package_pt')){
			// 	state.package_pt = uni.getStorageSync('package_pt');
			// }
			return Number(state.package_pt) || 0;
		},
		getPacketZy(state){
			// package_zy==0 从缓存取 
			// if(state.package_zy == 0 && uni.getStorageSync('package_zy')){
			// 	state.package_zy = uni.getStorageSync('package_zy');
			// }
			return Number(state.package_zy) || 0;
		},
		getPacketMt(state){
			// package_mt==0 从缓存取 
			// if(state.package_mt == 0 && uni.getStorageSync('package_mt')){
			// 	state.package_mt = uni.getStorageSync('package_mt');
			// }
			return Number(state.package_mt) || 0;
		},
		getPacketHh(state){
			// package_hh==0 从缓存取 
			// if(state.package_hh == 0 && uni.getStorageSync('package_hh')){
			// 	state.package_hh = uni.getStorageSync('package_hh');
			// }
			return Number(state.package_hh) || 0;
		},
		getClickID(state){
			return state.click_id
		}
	},
	actions: {

	}

})
